<?php

namespace App\Console\Commands\ThirdOrder;

use App\Console\Base;
use App\Services\ThirdAPI\GNSAPIService;
use App\Models\Game;
use App\Models\PartnerConfig;

class GNSBonusPoolProcesser extends Base
{
    protected $signature = self::PREFIX . 'gnsBonusPool';
    protected $description = 'GNS奖池拉取';
    /**
     * 执行控制台命令。
     *
     * @return mixed
     */
    public function handle()
    {
        $game_code = 'M4-0087';//GNS游戏目前只有这一个游戏有奖池
        $this->gnsService = new GNSAPIService();
        $ret = $this->gnsService->getBonusPool($game_code);
        $bonus_pool = ($ret['incrementMini']+$ret['incrementMinor']+$ret['incrementMajor']+$ret['incrementGrand'])*10;//GNS奖池单位是分，X10转为厘
        $gameModel = Game::where(['partner_name' => 'GNS', 'game_code' => $game_code])->first();
        $gameModel->jackpot = $bonus_pool;
        $partnerModel = PartnerConfig::where(['partner_name' => 'GNS'])->first();
        $partnerModel->jackpot = $bonus_pool;
        if($partnerModel->save()&&$gameModel->save()){
            $this->info("===== Save Data success: GNS奖池拉取成功");
        } else {
            $this->error("===== Save Data success: GNS奖池拉取失败,接口返回数据:". json_encode($ret));
        }
    }


}
